<template name="poster">
	<view class="posterShade" @tap="closeShade">
		<view class="posterBg">
			<view class="canvasImg">
				<view class="posterCon leaf-padded-t-15 leaf-padded-b-15">
					<view class="leaf-font-size-20 leaf-padded-t-5 leaf-padded-b-5">官宣啦</view>
					<view class="leaf-font-size-12">iLove—您的专属情侣恋爱空间</view>
					<view class="leaf-padded-20">
						<view style="margin-left: 10rpx;">
							<image :src="posterInfo.avatarUrl" mode="widthFix"></image>
							<image :src="posterInfo.love_avatarUrl" style="margin-left: -20rpx;" mode="widthFix"></image>
						</view>
						<view class="leaf-font-size-12 leaf-padded-t-5 leaf-padded-b-5">{{posterInfo.nickName}} & {{posterInfo.love_nickName}}</view>
						<view class="leaf-font-size-12 leaf-padded-b-5">{{posterInfo.bind_time}} 我们正式成为幸福的一对~</view>
					</view>
					<view class="leaf-font-size-18 leaf-padded-t-10 leaf-padded-b-10">我们在一起 已经</view>
					<view class="leaf-font-size-16"><text>{{posterInfo.differ_time}}</text>天</view>
				</view>
				<view class="posterFoot">
					<view><image src="../../static/code.png" mode="widthFix"></image></view>
					<view class="leaf-font-size-14 leaf-padded-l-5">快来『iLove』为我们祝福吧</view>
				</view>
			</view>
			<canvas class="canvasImg" canvas-id="myCanvas" :style="'width:'+canvasWidth+'px;height:'+canvasHeight+'px;position:absolute;top:0;left:0;'"/>
			<!-- <view class="posterBtn leaf-padded-t-20">
				<view @tap.stop="save">保存</view>
				<view>分享</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	// import html2canvas from '@/common/js/html2canvas.min.js'
	// import * as echarts from 'echarts'
	// import mpvueEcharts from 'mpvue-echarts'
	export default {
		name: "poster",
		props: {
			posterInfo: {
				type: Object,
				default() {
					return []
				}
			},
		},
		data() {
			return {
				canvasWidth:0,
				canvasHeight:0,
				info:{
					avatarUrl:'',
					love_avatarUrl:''
				}
			}
		},
		onReady() {
			uni.downloadFile({
			    url: this.posterInfo.avatarUrl,
			    success: (res) => {
			        if (res.statusCode === 200) {
						this.info.avatarUrl = res.tempFilePath;
			        }
			    }
			});
			uni.downloadFile({
			    url: this.posterInfo.love_avatarUrl,
			    success: (res) => {
			        if (res.statusCode === 200) {
						this.info.love_avatarUrl = res.tempFilePath;
			        }
			    }
			});
		},
		methods:{
			/**
			 * @author smallfour
			 * @description 关闭遮罩
			 */
			closeShade:function(){
				this.$emit("FcloseShade");
			},
			
			/**
			 * @author smallfour
			 * @description 保存
			 */
			save:function(){
				const that = this;
				// uni.showLoading({
				// 	title: '图片保存中...',
				// })
				
				// let info = uni.createSelectorQuery().in(this).select(".canvasImg");
				// info.boundingClientRect(function(data) {
				// 	that.canvasHeight = data.height;
				// 	that.canvasWidth = data.width;
				// 	let ctx = uni.createCanvasContext('myCanvas',that);
				// 	ctx.setStrokeStyle('#FF0000');
				// 	ctx.rect(0, 0, 0, 0);
				// 	ctx.setFillStyle('#FFFFFF');
				// 	ctx.setTextAlign('center');
				// 	ctx.setFontSize(uni.upx2px(40));
				// 	ctx.fillText('官宣啦', that.canvasWidth/2 , uni.upx2px(80));
				// 	ctx.setFontSize(uni.upx2px(24));
				// 	ctx.fillText('iLove—您的专属情侣恋爱空间', that.canvasWidth/2 , uni.upx2px(124));
					
				// 	ctx.arc(that.canvasWidth/2 - uni.upx2px(38),  uni.upx2px(224), uni.upx2px(50), 0, Math.PI * 2);
				// 	ctx.clip();
				// 	ctx.drawImage(that.info.avatarUrl, that.canvasWidth/2 - uni.upx2px(90), uni.upx2px(174),uni.upx2px(100),uni.upx2px(100));
					
				// 	// ctx.arc(that.canvasWidth/2 + uni.upx2px(50),  uni.upx2px(224), uni.upx2px(50), 0, Math.PI * 2);
				// 	// ctx.clip();
				// 	// ctx.drawImage(that.info.love_avatarUrl, that.canvasWidth/2 - uni.upx2px(0), uni.upx2px(174),uni.upx2px(100),uni.upx2px(100));
					
				// 	ctx.drawImage('../../static/code.png', uni.upx2px(20), that.canvasHeight - uni.upx2px(150),uni.upx2px(150),uni.upx2px(150));
				// 	ctx.draw();
				// }).exec();
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F4F4F4;
	}
	.posterShade{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100vh;
		.canvasImg{
			border-radius: 14rpx;
			overflow: hidden;
			box-shadow: 0 0 10rpx #ccc;
			background: #ec6e81;
		}
		.posterBg{
			position: absolute;
			top: 240rpx;
			width: calc(100% - 160rpx);
			margin:0 80rpx;
			text-align: center;
			.posterCon{
				color: #FFFFFF;
				background: #ec6e81;
				text{
					font-size: 60rpx;
				}
				image{
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
					border: 2rpx solid #FFFFFF;
				}
			}
			.posterFoot{
				background: #FFFFFF;
				display: flex;
				align-items: center;
				padding: 10rpx 20rpx;
				image{
					width: 150rpx;
					height: 150rpx;
				}
			}
			
			.posterBtn{
				display: flex;
				text-align: center;
				view{
					flex:1;
					margin: 0 30rpx;
					padding: 14rpx 0;
					border-radius: 50rpx;
					border: 2rpx solid #ec6e81;
				}
				view:nth-child(1){
					color: #ec6e81;
				}
				view:nth-child(2){
					background-color: #ec6e81;
					color: #FFFFFF;
				}
			}
		}
	}
</style>
